package com.gxa.www.cl.controller;

import com.gxa.www.cl.common.base.RespResult;
import com.gxa.www.cl.domain.vo.Person;
import com.gxa.www.cl.service.impl.PurchaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class PurchaseController {

    @Autowired
    private PurchaseServiceImpl purchaseService;

    @GetMapping("/ruku/user/ruku/rukuCaiName")
    public RespResult<List<Person>> queryCaiName(){
        System.out.println("=======采购人========");
        System.out.println(purchaseService.queryCaiName().toString());
        return RespResult.success("成功返回",purchaseService.queryCaiName());
    }
    @PostMapping("/ruku/user/ruku/rukuAdd")
    public Map<String, Object> addPurchase(@RequestBody Map<String, Object> formData) {
        try {
            purchaseService.addPurchase(formData); // 确保这里接收的 formData 包含负责人数据
            Map<String, Object> response = new HashMap<>();
            response.put("code", 0);
            response.put("message", "采购单添加成功");
            return response;
        } catch (Exception e) {
            Map<String, Object> response = new HashMap<>();
            response.put("code", 1);
            response.put("message", "采购单添加失败");
            return response;
        }
    }
}